package com.scut.shangxueguan.contrlller.user;

import com.scut.shangxueguan.pojo.Files;
import com.scut.shangxueguan.pojo.Result;
import com.scut.shangxueguan.service.IFileService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RequestMapping("user/file")
@RestController
@RequiredArgsConstructor
@Slf4j
public class UserFileController {

    private final IFileService fileService;

    @GetMapping
    public String test() {
        return "test";
    }

    @GetMapping("/getAll")
    public List<Files> getAll() {
        log.info("获取全部文件信息！");
        return fileService.getAllFile();
    }

    @GetMapping("/download")
    public Result downloadFile(String fileName, HttpServletResponse response) throws IOException {
        log.info("文件下载。。。。");
        return fileService.downloadFile(fileName, response);
    }
}
